# -*- coding:utf-8 -*-


class Student:
    """ 个人信息 """
    def __init__(self):
        self.name = "空"  # 姓名
        self.no = "空"  # 学号
        self.gender = "未设置"  # 性别
        self.id = "空"  # 身份证号
        self.nation = "空"  # 民族
        self.hometown = "空"  # 籍贯
        self.period = "空"  # 入学时期
        self.department = "空"  # 系
        self.major = "空"  # 专业
        self.course_list = []  # 课程列表

    def __str__(self):
        return ("{" + str(self.name) + "," + str(self.no) + "," + str(self.period) + "," +
                str(self.major) + "," + str(self.id) + "," + str(self.hometown) +
                "}").encode("utf8")

    def calculate_got_point(self):
        """获得的总学分"""
        all_point = 0
        for course in self.course_list:
            # 及格的都算学分(及格的也不会重修)
            if course.score >= 60:
                all_point += course.point
        return all_point

    def calculate_gpa(self):
        """计算平均学分绩"""
        grade_point_sum = 0
        all_got_point = 0
        for course in self.course_list:
            # 统计学分的课程(有效的课程)剔除通选课 与 大学体育
            if course.attribute != u"通识教育选修课" and str(course.name).find(u"体育") == -1\
                    and course.attribute != u"辅修":
                grade_point = 0
                if 90 <= course.score <= 100:
                    grade_point = 4
                elif 85 <= course.score <= 89:
                    grade_point = 3.7
                elif 82 <= course.score <= 84:
                    grade_point = 3.3
                elif 78 <= course.score <= 81:
                    grade_point = 3.0
                elif 75 <= course.score <= 77:
                    grade_point = 2.7
                elif 72 <= course.score <= 74:
                    grade_point = 2.3
                elif 68 <= course.score <= 71:
                    grade_point = 2.0
                elif 65 <= course.score <= 67:
                    grade_point = 1.7
                elif 62 <= course.score <= 64:
                    grade_point = 1.3
                elif 60 <= course.score <= 61:
                    grade_point = 1.0
                else:
                    grade_point = 0

                grade_point_sum += course.point * grade_point
                if course.score >= 60:
                    all_got_point += course.point

        return grade_point_sum / all_got_point
